package com.example.wangyongdong.bearsqlitedemo.db;

import com.example.wangyongdong.bearsqlitedemo.sqlorm.RecordOperationSQL;
import com.example.wangyongdong.bearsqlitedemo.entity.CarEntity;
import com.example.wangyongdong.bearsqlitedemo.entity.MoneyEntity;
import com.example.wangyongdong.bearsqlitedemo.entity.RecordEntity;
import com.example.wangyongdong.bearsqlitedemo.Interface.TableCarOperation;
import com.example.wangyongdong.bearsqlitedemo.app.BearApplication;
import com.example.wangyongdong.bearsqlitedemo.Interface.TableRecordOperation;

import java.util.List;

/**
 * Created by wangyongdong on 2017/4/13.
 */

public class DatabaseTool implements TableCarOperation, TableRecordOperation {

    private BearSQLiteHelper mHelper;
    private TableCarOperation mCarOperation;
    private TableRecordOperation mRecordOperation;

    private static class SingletonHolder {
        private static final DatabaseTool INSTANCE = new DatabaseTool();
    }

    public static DatabaseTool getInstance() {
        return SingletonHolder.INSTANCE;
    }

    private DatabaseTool() {
        mHelper = new BearSQLiteHelper(BearApplication.getsContext());
        mCarOperation = new CarOperationAndroid(mHelper);
        mRecordOperation = new RecordOperationSQL(mHelper);
    }

    //  Car  查询
    public void addCar(CarEntity car) {
        mCarOperation.addCar(car);
    }

    public void removeCar(int id) {
        mCarOperation.removeCar(id);
    }

    public void updateCar(CarEntity car) {
        mCarOperation.updateCar(car);
    }

    public List<CarEntity> queryCars() {
        return mCarOperation.queryCars();
    }

    @Override
    public CarEntity querySelectedCar() {
        return mCarOperation.querySelectedCar();
    }

    @Override
    public void changeSelectedCar(int id) {
        mCarOperation.changeSelectedCar(id);
    }

    @Override
    public void changeSelectedCar(CarEntity newSelectedCar) {
        mCarOperation.changeSelectedCar(newSelectedCar);
    }

    // Record 查询
    @Override
    public void addRecord(RecordEntity record) {
        mRecordOperation.addRecord(record);
    }

    @Override
    public void removeRecord(int id) {
        mRecordOperation.removeRecord(id);
    }

    @Override
    public void updateRecord(RecordEntity record) {
        mRecordOperation.updateRecord(record);
    }

    @Override
    public List<RecordEntity> queryCarAllRecord() {
        return mRecordOperation.queryCarAllRecord();
    }

    @Override
    public List<RecordEntity> queryCarYearRecord() {
        return mRecordOperation.queryCarYearRecord();
    }

    @Override
    public List<RecordEntity> queryCarHalfYearRecord() {
        return mRecordOperation.queryCarHalfYearRecord();
    }

    @Override
    public List<RecordEntity> queryCarThreeMonthRecord() {
        return mRecordOperation.queryCarThreeMonthRecord();
    }

    @Override
    public List<MoneyEntity> queryEachYearMoney() {
        return mRecordOperation.queryEachYearMoney();
    }

    @Override
    public List<MoneyEntity> queryEachMonthMoney() {
        return mRecordOperation.queryEachMonthMoney();
    }

}
